<template>
	<view class="root-box root-container root-page-top">
		<uv-navbar title="收费标准" autoBack placeholder bgColor="transparent" :fixed="false" />
		<view class="content" v-if="fees">
			<view class="cell-page">
				<view class="uv-page__item">
					
					<view class="txt-box">
						<text>基础收费</text>
					</view>
					
					<uv-cell-group :customStyle="{background:'#fff'}">
						<uv-cell title="代收快递" :value="fees.substitute_delivery+'元起'" :isLink="true" @click="onSetFee('substitute_delivery')"></uv-cell>
						<uv-cell title="代取外卖" :value="fees.substitute_takeout+'元起'" :isLink="true" @click="onSetFee('substitute_takeout')"></uv-cell>
						<uv-cell title="代购商品" :value="fees.substitute_goods+'元'" :isLink="true" @click="onSetFee('substitute_goods')"></uv-cell>
						<uv-cell title="代送" :value="fees.proxy_delivery+'元'" :isLink="true" @click="onSetFee('proxy_delivery')"></uv-cell>
					</uv-cell-group>
					
					
					<view class="txt-box">
						<text>增加收费</text>
					</view>
					
					<uv-cell-group :customStyle="{background:'#fff'}">
						<uv-cell title="雨天" :value="fees.increased_cost_rain+'元'" :isLink="true" @click="onSetFee('increased_cost_rain')"></uv-cell>
						<uv-cell title="无电梯" :value="fees.increased_cost_no_elevator+'元'" :isLink="true" @click="onSetFee('increased_cost_no_elevator')"></uv-cell>
					</uv-cell-group>
					
					<view class="txt-box">
						<text>代办服务</text>
					</view>
					
					<uv-cell-group :customStyle="{background:'#fff'}">
						<uv-cell title="宠物喂养" :value="fees.pet_feeding+'元'" :isLink="true" @click="onSetFee('pet_feeding')"></uv-cell>
						<uv-cell title="宠物帮遛" :value="fees.pet_walking_assistance+'元'" :isLink="true" @click="onSetFee('pet_walking_assistance')"></uv-cell>
						<uv-cell title="衣服干洗" :value="fees.dry_cleaning_of_clothes+'元'" :isLink="true" @click="onSetFee('dry_cleaning_of_clothes')"></uv-cell>
						<uv-cell title="家庭快修" :value="fees.family_quick_repair+'元'" :isLink="true" @click="onSetFee('family_quick_repair')"></uv-cell>
						<uv-cell title="陪护作业" :value="fees.accompanying_homework+'元'" :isLink="true" @click="onSetFee('accompanying_homework')"></uv-cell>
						<uv-cell title="到家家教" :value="fees.home_tutoring+'元'" :isLink="true" @click="onSetFee('home_tutoring')"></uv-cell>
						<uv-cell title="带娃煮饭" :value="fees.cooking_with_children+'元'" :isLink="true" @click="onSetFee('cooking_with_children')"></uv-cell>
						<uv-cell title="其它家事" :value="fees.other_household_matters+'元'" :isLink="true" @click="onSetFee('other_household_matters')"></uv-cell>
					</uv-cell-group>
                </view>
            </view>
			<view class="button-box">
			    <tui-button type="danger" shape="circle" height="60rpx" size="24" width="700rpx" @click="onSaveFree">保存</tui-button>
				
            </view>
			
			<uv-popup ref="freePopup" round="10" :closeOnClickOverlay="false" :closeable="true"
				closeIconPos="top-right" @change="changePopup">
				<view class="free-set-box">
					<view class="mt-30">
					<NumberInput v-model="selfInputValue" placeholder="请输入数字" mode="decimal2" />
					</view>
					<view class="free-box">
						<tui-button type="danger" width="300rpx" height="60rpx" size="30" @click="setFee">确定</tui-button>
					</view>
				</view>
			</uv-popup>
			
			
		</view>

	</view>
</template>

<script setup>
	import {
		ref,reactive
	} from 'vue'
	import {
		useUserStore,useAgentStore
	} from '@/store'
	import {
		storeToRefs
	} from 'pinia'
	
	
	
	import { setEmptyProperties } from '@/util/tools.js'
	import NumberInput from '@/components/NumberInput.vue'
	import { detailFeeStandards,setFeeStandards } from '@/api/other.js'
    const freePopup = ref(null)
	const user = useUserStore()
	const agent= useAgentStore()
	const fees = ref(null)
	const selfKey = ref('')
	const selfInputValue = ref(null)
	const {
		token,
		userInfo
	} = storeToRefs(user)
	const changePopup=(sign)=>{
		if(!sign.show){
			 selfInputValue.value=0;
		}
		
	}
	const getDetailFeeStandards= async()=>{
		const result = await detailFeeStandards()
		if (result.code == 200) {
			console.log('-----detailFeeStandards--',result)
			fees.value = result.result
			agent.setFees(fees.value)
		}
	}
	
	const onSetFee = (key) => {
		console.log('---self--key---',key)
		selfKey.value = key
		freePopup.value?.open('center')
	}
	
	const setFee = () => {
	  fees.value[selfKey.value] = selfInputValue.value
	  console.log('---fees.value--',fees.value)
	
	  selfInputValue.value=0;
	  freePopup.value?.close()
	}
	const onSaveFree= async()=>{
		let param=setEmptyProperties(fees.value,0)
		console.log('---onsavefree---',param)
		
		const result = await setFeeStandards(param)
		if (result.code == 200) {
			agent.setFees(fees.value)
			uni.$uv.toast('保存成功')
			
		}else{
			uni.$uv.toast('保存失败')
		}
	}
	
	const init = async () => {
        await getDetailFeeStandards()
	}

	init()
</script>

<style lang="scss" scoped>
	
	.txt-box{
		display: flex;
		padding: 20rpx 30rpx; 
		box-sizing: border-box;
		color: #333;
		font-size: 28upx;
		font-weight: 600;
	}
	.root-box {


		.content {
			box-sizing: border-box;
			background-color: $uv-bg-color;
		}


	}

	.uv-page {
		padding: 0;

		&__item {

			&__title {
				color: $uv-tips-color;
				background-color: $uv-bg-color;
				padding: 30rpx;
				font-size: 30rpx;

				&__slot-title {
					color: $uv-primary;
					font-size: 28rpx;
				}
			}


		}


	}
	
	.button-box{
		display: flex;
		
		padding: 30rpx;
		box-sizing: border-box;
	}
	
	.free-set-box{
		background-color: #fff;
		padding: 100rpx 30rpx 50rpx 30rpx;
		box-sizing: border-box;
		width: 600rpx;
		display: flex;
		flex-direction: column;
		justify-content: flex-start;
		align-items: center;
		
	}
	
	.free-box{
		margin-top: 40rpx;
	}
	

</style>